package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.common.entity.Department;

import java.util.List;

public interface DepartmentMapper {

    // 插入新部门
    @Insert("INSERT INTO department (tenant_id, department_name, parent_department_id, status, created_at, updated_at) " +
            "VALUES (#{tenantId}, #{departmentName}, #{parentDepartmentId}, #{status}, #{createdAt}, #{updatedAt})")
    void insertDepartment(Department department);

    // 根据ID查询部门
    @Select("SELECT * FROM department WHERE department_id = #{departmentId} AND deleted_at IS NULL")
    Department getDepartmentById(@Param("departmentId") Long departmentId);

    // 查询某租户下的所有部门
    @Select("SELECT * FROM department WHERE tenant_id = #{tenantId} AND deleted_at IS NULL")
    List<Department> getDepartmentsByTenantId(@Param("tenantId") Long tenantId);

    // 逻辑删除部门
    @Update("UPDATE department SET deleted_at = NOW() WHERE department_id = #{departmentId}")
    void deleteDepartment(@Param("departmentId") Long departmentId);
}
